package com.ctrip.ec.biz.dao.image;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.image.ImageEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class ImageDao extends DaoBase<ImageEntity> {
    public ImageDao() {
        super(ImageEntity.class);
    }
    public ImageDao(DbAccess db) {
        super(ImageEntity.class,db);
    }

    public void inUse(Long id) throws SQLException {
        String sql = "update "  + this.getTableName() + " set in_use=1 where id = ?";
        this.db.execute(sql,id);
    }

    public  void unUse(Long id) throws SQLException {
        String sql = "update " + this.getTableName() + " set in_use = 0 where id = ?";
        this.db.execute(sql,id);
    }

    public void unUse(List<Long> ids) throws SQLException {
        if(ids != null && ids.size()>0 ) {
            String strIds = IdConvert.join(ids);
            String sql = "update " + this.getTableName() + " set in_use = 0 where id in (" + strIds + ")";
            this.db.execute(sql);
        }
    }
}
